﻿<UserControl
    x:Class="Srk.BetaseriesApiApp.Views.Badges"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    mc:Ignorable="d" 
    d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <TextBlock Margin="4" TextWrapping="Wrap" FontSize="10"><Run Text="The API does not provide direct access to badges. Clicking the Update button will fetch the global website timeline trying to find new badge keys. All found badge keys will be saved. You are supposed to click update at different times to find new badges or to use automatic update (10 minutes interval)."/></TextBlock>

        <WrapPanel Grid.Row="1" Orientation="Horizontal">
            <ToggleButton IsChecked="{Binding IsAutoUpdateEnabled}" 
                                      Margin="4" Content="Auto update"/>
            <Button Command="{Binding UpdateCommand}" 
                                HorizontalAlignment="Left" Margin="4" Content="Update"/>
            <Button Command="{Binding UpdateSelfCommand}" 
                                HorizontalAlignment="Left" Margin="4" Content="Update from my profile"/>
            <Button Command="{Binding UpdateFriendsCommand}" 
                                HorizontalAlignment="Left" Margin="4" Content="Update from friends"/>
            <Button Command="{Binding UpdateUserCommand}" 
                                HorizontalAlignment="Left" Margin="4">
                <StackPanel Orientation="Horizontal">
                    <TextBlock xml:space="preserve"><Run Text="Update from user "/></TextBlock>
                    <TextBox Text="{Binding Username, UpdateSourceTrigger=PropertyChanged}" 
                                         Width="80" FontSize="8" IsEnabled="{Binding IsNotBusy}" />
                </StackPanel>
            </Button>
        </WrapPanel>

        <WrapPanel Grid.Row="2" Orientation="Horizontal">
            <CheckBox Content="Verified" IsThreeState="True"
                                  IsChecked="{Binding FilterVerified}" Margin="8,4,4,4" />
            <CheckBox Content="Implemented" IsThreeState="True"
                                  IsChecked="{Binding FilterImplemented}" Margin="8,4,4,4" />
            <CheckBox Content="Name translated" IsThreeState="True"
                                  IsChecked="{Binding FilterNameTranslated}" Margin="8,4,4,4" />
            <CheckBox Content="Description translated" IsThreeState="True"
                                  IsChecked="{Binding FilterDescriptionTranslated}" Margin="8,4,4,4" />
            <CheckBox Content="Require attention" IsThreeState="True"
                                  IsChecked="{Binding FilterRequireAttention}" Margin="8,4,4,4" />
        </WrapPanel>

        <ListView Grid.Row="3" Margin="4"
                              ItemsSource="{Binding BadgesCV}"
                              ItemContainerStyleSelector="{StaticResource BadgeListViewItemStyleSelector}">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="ServiceName" 
                                                DisplayMemberBinding="{Binding ServiceName}" />
                    <GridViewColumn Header="InternalType" 
                                                DisplayMemberBinding="{Binding InternalType}" />
                    <GridViewColumn Header="Implementation" 
                                                DisplayMemberBinding="{Binding Converter={StaticResource ImplementedVerifiedConverter}}"
                                                CellTemplate="{StaticResource BoolGridViewColumnWithColors}" />
                    <GridViewColumn Header="TranslatedName" 
                                                DisplayMemberBinding="{Binding TranslatedName}" />
                    <GridViewColumn Header="TranslatedDescription" 
                                                DisplayMemberBinding="{Binding TranslatedDescription}" />
                </GridView>
            </ListView.View>
        </ListView>

        <GridSplitter Grid.Row="4" ResizeBehavior="PreviousAndNext" ResizeDirection="Auto" Height="4" Background="Gray" HorizontalAlignment="Stretch" />

        <Grid Grid.Row="5">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
            </Grid.RowDefinitions>

            <StackPanel Grid.Row="1" Orientation="Horizontal" Margin="2"
                                    HorizontalAlignment="Right" VerticalAlignment="Top" Panel.ZIndex="10">
                <!--<TextBlock Margin="4,4,16,4">Log</TextBlock>-->
                <TextBox Text="{Binding LogSearch, UpdateSourceTrigger=PropertyChanged}" Width="240" Margin="4" />
                <Button Content="Clear" Command="{Binding ClearLogCommand}" Margin="4,4,32,4" />
            </StackPanel>

            <ScrollViewer Grid.Row="1" Margin="2">
                <ItemsControl ItemsSource="{Binding LogCV}">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Border BorderBrush="Gray" BorderThickness="0,0,0,1">
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding Date}" VerticalAlignment="Center" Margin="4" />
                                    <ItemsControl ItemsSource="{Binding Entries}">
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate>
                                                <StackPanel Orientation="Horizontal">
                                                    <TextBlock FontWeight="Bold" Text="{Binding Key}" Margin="2" />
                                                    <ItemsControl ItemsSource="{Binding Value}">
                                                        <ItemsControl.ItemsPanel>
                                                            <ItemsPanelTemplate>
                                                                <WrapPanel Orientation="Horizontal" />
                                                            </ItemsPanelTemplate>
                                                        </ItemsControl.ItemsPanel>
                                                        <ItemsControl.ItemTemplate>
                                                            <DataTemplate>
                                                                <TextBlock Text="{Binding}" Margin="2,2,8,2" />
                                                            </DataTemplate>
                                                        </ItemsControl.ItemTemplate>
                                                    </ItemsControl>
                                                </StackPanel>
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                                </StackPanel>
                            </Border>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </ScrollViewer>
        </Grid>

        <ItemsControl Grid.Row="6" Margin="4"
                                  ItemsSource="{Binding Stats}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel Orientation="Horizontal" />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Border BorderBrush="Gray" BorderThickness="1" Padding="4" Margin="2,2,4,2">
                        <Border.Background>
                            <LinearGradientBrush StartPoint=".5,0" EndPoint=".5,1">
                                <GradientStop Color="LightGray" Offset="0" />
                                <GradientStop Color="White" Offset=".1" />
                                <GradientStop Color="#ffC7D5EA" Offset="1" />
                            </LinearGradientBrush>
                        </Border.Background>
                        <TextBlock Text="{Binding}" />
                    </Border>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>

        <TextBlock Grid.Row="7" Text="{Binding StatusMessage}" Margin="4" />
    </Grid>
</UserControl>
